package com.example.imooccommon.store;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author Anita
 * 七牛云上传图像和查看图像
 * @Date 2018/1/18 10:04
 */
@Component
public class QiniuStorage {


    @Autowired
    private QiniuWrapper qiniuWrapper;

    /**
     * 上传单张图片；返回上传图片的key
     * @param buff
     * @return
     */
    public  String uploadImage(byte[] buff){
        String key = QiniuKeyGenerator.generateKey(); ///default/all/0/b5ef8be83f124bd9880c9c1b87fb03bf
        key = qiniuWrapper.upload(buff,key,false);
        return key;
    }

    // test调用uploadImage传入图片的byte[],然后生成一个key(/default/all/0/b5ef8be83f124bd9880c9c1b87fb03bf)
    //然后再根据传的byte[]判断是什么类型，给文件加后缀，形成完整的key，然后利用七牛的sdk上传，会得到一个返回的key
    //实际链接为http://orsoyruqj.bkt.clouddn.com//default/all/0/b5ef8be83f124bd9880c9c1b87fb03bf.jpeg

    /**
     *获取图片链接
     * @param key
     * @return
     */
    public  String getUrl(String key){
        return qiniuWrapper.getUrl(key);
    }


}
